// 基地址
const BASEURL = 'https://www.uinav.com/api/public/v1/'

const request = ({
  url,
  method = 'GET',
  data = {},
  header = {},
  tip = '拼命加载中。。。',
  isPullDownRefresh = false
}) => {
  return new Promise((resolve, reject) => {
    if (!isPullDownRefresh) {
      uni.showLoading({
        title: tip,
        mask: true
      })
    }
    const token = uni.getStorageSync('token')
    if(token){
      header.Authorization=token
    }
    uni.request({
      url: `${BASEURL}${url}`,
      data,
      header,
      method,
      // 是不是https
      // sslVerify: true,
      success: ({ data, statusCode, header }) => {
        resolve(data)
      },
      fail: error => {
        reject(error)
      },
      complete: () => {
        if (!isPullDownRefresh) {
          uni.hideLoading()
        }
      }
    })
  })
}
uni.$request = request
